﻿
@{
    ViewBag.Title = "SignUp";
    Layout = "~/Views/_layouts/_LayoutMain.cshtml";
}
<script src="~/scripts/md5.js"></script>
<div style="padding:80px">
    <div class="layui-card">
        <div class="layui-card-header">注册</div>
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="Login" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="LoginID" lay-verify="title" placeholder="请输入账号" class="layui-input">
                    </div>
                    <div style="float: left; display: block;  padding: 9px 0!important;  line-height: 20px;  margin-right: 10px;color: #999!important;">至少6位数字或字符，不能包含特殊字符</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="PassWords" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">请填写6到18位密码</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="ConfirmPassWords" lay-verify="pass" autocomplete="off" placeholder="请再次输入密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-inline">
                        <select name="Sex" lay-verify="required">
                            <option value=""></option>
                            <option value="0">女</option>
                            <option value="1">男</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出生日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Birthday" id="date" lay-verify="required|date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">验证码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="ValidCode" lay-verify="required" placeholder="请输入验证码" class="layui-input">
                    </div>
                    <div class="layui-form-mid" style="padding: 0!important;">
                        <img class="fly-imagecode" src="ValidImage" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" lay-filter="formRegister" lay-submit="">注册</button>
                    <span style="padding-left:20px;"></span>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layer', 'laydate'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#date'
        });

        //自定义验证规则
        form.verify({
            title: [/^[a-zA-Z0-9_-]{6,18}$/, '至少6位数字或字符，不能包含特殊字符']
          , pass: [/(.+){6,18}$/, '密码必须6到18位']
          , content: function (value) {
              layedit.sync(editIndex);
          }
        });
        //监听提交
        form.on('submit(formRegister)', function (data) {
            if (data.field.PassWords == data.field.ConfirmPassWords) {
                data.field.PassWords = hex_md5(data.field.PassWords);
                var index = layer.load();
                $.ajax({
                    url: 'Register',
                    type: 'POST',
                    data: data.field,
                    dataType: 'json',
                    success: function (a, b) {
                        layer.close(index);
                        if (a.code == 0)
                            window.location.href = 'SignIn';
                        else {
                            layer.msg(a.msg);
                            $('.fly-imagecode').src = 'ValidImage?t=' + new Date().getTime();
                        }
                    },
                    error: function (a, b, c) {
                        layer.close(index);
                        layer.msg(b);
                    }
                });

            } else {
                layer.msg('两次密码不一致');
            }
            return false;
        });

        //刷新图形验证码
        $('body').on('click', '.fly-imagecode', function () {
            this.src = 'ValidImage?t=' + new Date().getTime();
        });
    });
</script>

